﻿namespace FluentMvc
{
    using System;

    public class RuleInitializer<TModel, TProperty> where TModel : class
    {
        private readonly ValidationSetting<TModel> context;

        internal RuleInitializer(ValidationSetting<TModel> context)
        {
            this.context = context;
        }

        public RuleInitializer<TModel,TProperty> StopOnFail()
        {
            context.StopChainOnFail = true;
            return this;
        }

        public RuleInitializer<TModel,TProperty> Message(string message)
        {
            context.Message = message;
            context.GetMessage = null;
            return this;
        }
       
        public RuleInitializer<TModel,TProperty> Message(Func<string> getmessage)
        {
            context.Message = null;
            context.GetMessage = getmessage;
            return this;
        }

        public RuleInitializer<TModel,TProperty> Ignore(Func<TModel,bool> predicate)
        {
            context.Ignore = predicate;
            return this;
        }

        public RuleInitializer<TModel,TProperty> When(Func<TModel,bool> predicate)
        {
            context.When = predicate;
            return this;
        }
    }
}